{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n",
      "/Users/vanpelt/.pyenv/versions/3.6.4/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n",
      "  return f(*args, **kwds)\n",
      "/Users/vanpelt/.pyenv/versions/3.6.4/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n",
      "  return f(*args, **kwds)\n"
     ]
    }
   ],
   "source": [
    "from keras import layers\n",
    "from keras.models import Model\n",
    "import keras\n",
    "import numpy as np\n",
    "\n",
    "init = keras.initializers.RandomNormal(seed=1)\n",
    "inp = layers.Input((5, 1))\n",
    "out1 = layers.GRU(3, return_sequences=True, kernel_initializer=init, recurrent_initializer=init)(inp)\n",
    "out2= layers.GRU(3, return_sequences=False, kernel_initializer=init, recurrent_initializer=init)(inp)\n",
    "m1 = Model(inp, [out1, out2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[array([[[ 0.00148446, -0.00529137, -0.001807  ],\n",
       "         [ 0.00379733, -0.01328251, -0.00453949],\n",
       "         [ 0.00656812, -0.02265439, -0.00774633],\n",
       "         [ 0.00958988, -0.03273204, -0.01119637],\n",
       "         [ 0.01274805, -0.04316805, -0.014771  ]]], dtype=float32),\n",
       " array([[ 0.01274805, -0.04316805, -0.014771  ]], dtype=float32)]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "in_data = np.array([0.1,0.2,0.3,0.4,0.5]).reshape((1,5,1))\n",
    "m1.predict(in_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/100\n",
      "1/1 [==============================] - 1s 893ms/step - loss: 4.8180e-08\n",
      "Epoch 2/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 7.0771e-07\n",
      "Epoch 3/100\n",
      "1/1 [==============================] - 0s 7ms/step - loss: 1.6701e-06\n",
      "Epoch 4/100\n",
      "1/1 [==============================] - 0s 7ms/step - loss: 3.3612e-07\n",
      "Epoch 5/100\n",
      "1/1 [==============================] - 0s 8ms/step - loss: 2.5461e-07\n",
      "Epoch 6/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 8.8923e-07\n",
      "Epoch 7/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 6.6962e-07\n",
      "Epoch 8/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 4.6714e-07\n",
      "Epoch 9/100\n",
      "1/1 [==============================] - 0s 13ms/step - loss: 4.1562e-07\n",
      "Epoch 10/100\n",
      "1/1 [==============================] - 0s 8ms/step - loss: 2.3144e-07\n",
      "Epoch 11/100\n",
      "1/1 [==============================] - 0s 7ms/step - loss: 1.5412e-07\n",
      "Epoch 12/100\n",
      "1/1 [==============================] - 0s 7ms/step - loss: 3.1293e-07\n",
      "Epoch 13/100\n",
      "1/1 [==============================] - 0s 7ms/step - loss: 3.8327e-07\n",
      "Epoch 14/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 2.3997e-07\n",
      "Epoch 15/100\n",
      "1/1 [==============================] - 0s 7ms/step - loss: 1.0587e-07\n",
      "Epoch 16/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 1.3247e-07\n",
      "Epoch 17/100\n",
      "1/1 [==============================] - 0s 11ms/step - loss: 1.9310e-07\n",
      "Epoch 18/100\n",
      "1/1 [==============================] - 0s 8ms/step - loss: 1.6948e-07\n",
      "Epoch 19/100\n",
      "1/1 [==============================] - 0s 7ms/step - loss: 1.2511e-07\n",
      "Epoch 20/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 1.0967e-07\n",
      "Epoch 21/100\n",
      "1/1 [==============================] - 0s 8ms/step - loss: 8.9338e-08\n",
      "Epoch 22/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 6.4364e-08\n",
      "Epoch 23/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 8.1154e-08\n",
      "Epoch 24/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 1.1794e-07\n",
      "Epoch 25/100\n",
      "1/1 [==============================] - 0s 4ms/step - loss: 1.0157e-07\n",
      "Epoch 26/100\n",
      "1/1 [==============================] - 0s 4ms/step - loss: 4.1230e-08\n",
      "Epoch 27/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 1.5311e-08\n",
      "Epoch 28/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 4.1277e-08\n",
      "Epoch 29/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 6.4377e-08\n",
      "Epoch 30/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 6.1658e-08\n",
      "Epoch 31/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 5.0076e-08\n",
      "Epoch 32/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 3.2097e-08\n",
      "Epoch 33/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 1.0019e-08\n",
      "Epoch 34/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 9.2985e-09\n",
      "Epoch 35/100\n",
      "1/1 [==============================] - 0s 4ms/step - loss: 3.4180e-08\n",
      "Epoch 36/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 4.6017e-08\n",
      "Epoch 37/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 2.8501e-08\n",
      "Epoch 38/100\n",
      "1/1 [==============================] - 0s 7ms/step - loss: 9.0654e-09\n",
      "Epoch 39/100\n",
      "1/1 [==============================] - 0s 8ms/step - loss: 6.3524e-09\n",
      "Epoch 40/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 1.1235e-08\n",
      "Epoch 41/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 1.7032e-08\n",
      "Epoch 42/100\n",
      "1/1 [==============================] - 0s 4ms/step - loss: 2.1983e-08\n",
      "Epoch 43/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 1.7184e-08\n",
      "Epoch 44/100\n",
      "1/1 [==============================] - 0s 4ms/step - loss: 4.8867e-09\n",
      "Epoch 45/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 1.6790e-09\n",
      "Epoch 46/100\n",
      "1/1 [==============================] - 0s 14ms/step - loss: 8.9328e-09\n",
      "Epoch 47/100\n",
      "1/1 [==============================] - 0s 11ms/step - loss: 1.2237e-08\n",
      "Epoch 48/100\n",
      "1/1 [==============================] - 0s 7ms/step - loss: 8.9661e-09\n",
      "Epoch 49/100\n",
      "1/1 [==============================] - 0s 9ms/step - loss: 6.1873e-09\n",
      "Epoch 50/100\n",
      "1/1 [==============================] - 0s 4ms/step - loss: 4.2445e-09\n",
      "Epoch 51/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 3.0862e-09\n",
      "Epoch 52/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 5.1231e-09\n",
      "Epoch 53/100\n",
      "1/1 [==============================] - 0s 4ms/step - loss: 6.5026e-09\n",
      "Epoch 54/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 3.8027e-09\n",
      "Epoch 55/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 2.0219e-09\n",
      "Epoch 56/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 3.3556e-09\n",
      "Epoch 57/100\n",
      "1/1 [==============================] - 0s 7ms/step - loss: 3.5795e-09\n",
      "Epoch 58/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 2.4072e-09\n",
      "Epoch 59/100\n",
      "1/1 [==============================] - 0s 4ms/step - loss: 2.1213e-09\n",
      "Epoch 60/100\n",
      "1/1 [==============================] - 0s 4ms/step - loss: 1.8785e-09\n",
      "Epoch 61/100\n",
      "1/1 [==============================] - 0s 4ms/step - loss: 1.7144e-09\n",
      "Epoch 62/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 2.4308e-09\n",
      "Epoch 63/100\n",
      "1/1 [==============================] - 0s 7ms/step - loss: 2.0688e-09\n",
      "Epoch 64/100\n",
      "1/1 [==============================] - 0s 8ms/step - loss: 6.1418e-10\n",
      "Epoch 65/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 6.4036e-10\n",
      "Epoch 66/100\n",
      "1/1 [==============================] - 0s 7ms/step - loss: 1.5882e-09\n",
      "Epoch 67/100\n",
      "1/1 [==============================] - 0s 3ms/step - loss: 1.5704e-09\n",
      "Epoch 68/100\n",
      "1/1 [==============================] - 0s 4ms/step - loss: 1.0881e-09\n",
      "Epoch 69/100\n",
      "1/1 [==============================] - 0s 4ms/step - loss: 5.8033e-10\n",
      "Epoch 70/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 2.1113e-10\n",
      "Epoch 71/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 7.3032e-10\n",
      "Epoch 72/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 1.2431e-09\n",
      "Epoch 73/100\n",
      "1/1 [==============================] - 0s 4ms/step - loss: 7.0470e-10\n",
      "Epoch 74/100\n",
      "1/1 [==============================] - 0s 8ms/step - loss: 1.4630e-10\n",
      "Epoch 75/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 2.5163e-10\n",
      "Epoch 76/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 4.6086e-10\n",
      "Epoch 77/100\n",
      "1/1 [==============================] - 0s 8ms/step - loss: 6.2272e-10\n",
      "Epoch 78/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 5.0346e-10\n",
      "Epoch 79/100\n",
      "1/1 [==============================] - 0s 4ms/step - loss: 1.0143e-10\n",
      "Epoch 80/100\n",
      "1/1 [==============================] - 0s 4ms/step - loss: 9.6398e-11\n",
      "Epoch 81/100\n",
      "1/1 [==============================] - 0s 4ms/step - loss: 3.6527e-10\n",
      "Epoch 82/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 3.3687e-10\n",
      "Epoch 83/100\n",
      "1/1 [==============================] - 0s 4ms/step - loss: 2.0566e-10\n",
      "Epoch 84/100\n",
      "1/1 [==============================] - 0s 7ms/step - loss: 1.3740e-10\n",
      "Epoch 85/100\n",
      "1/1 [==============================] - 0s 8ms/step - loss: 1.0054e-10\n",
      "Epoch 86/100\n",
      "1/1 [==============================] - 0s 8ms/step - loss: 1.8773e-10\n",
      "Epoch 87/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 2.0106e-10\n",
      "Epoch 88/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 8.3187e-11\n",
      "Epoch 89/100\n",
      "1/1 [==============================] - 0s 3ms/step - loss: 9.0865e-11\n",
      "Epoch 90/100\n",
      "1/1 [==============================] - 0s 4ms/step - loss: 1.2801e-10\n",
      "Epoch 91/100\n",
      "1/1 [==============================] - 0s 4ms/step - loss: 8.7246e-11\n",
      "Epoch 92/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 7.9151e-11\n",
      "Epoch 93/100\n",
      "1/1 [==============================] - 0s 7ms/step - loss: 6.6197e-11\n",
      "Epoch 94/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 6.4736e-11\n",
      "Epoch 95/100\n",
      "1/1 [==============================] - 0s 6ms/step - loss: 9.1857e-11\n",
      "Epoch 96/100\n",
      "1/1 [==============================] - 0s 8ms/step - loss: 4.7798e-11\n",
      "Epoch 97/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 1.6923e-11\n",
      "Epoch 98/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 5.4378e-11\n",
      "Epoch 99/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 5.8906e-11\n",
      "Epoch 100/100\n",
      "1/1 [==============================] - 0s 5ms/step - loss: 4.3218e-11\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<keras.callbacks.History at 0x12a69ff28>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m2 = Model(inp, out2)\n",
    "m2.compile(loss=\"mse\", optimizer=\"adam\")\n",
    "m2.fit(in_data, np.array([0.6,0.7,0.8]).reshape((1,3)), epochs=100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.6000006 , 0.70000726, 0.8000034 ]], dtype=float32)"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m2.predict(in_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.6888099, 0.7770717, 0.871939 ]], dtype=float32)"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m2.predict(np.array([0.4,0.5,0.6,0.7,0.8]).reshape((1,5,1)))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
